struct VSOUT
{
	float4 Position         : POSITION;
	float4 Diffuse			: COLOR;	
	float2 TexCoord0		: TEXCOORD0;
	float4 TexCoord1		: TEXCOORD1;
};

uniform sampler g_TextureSampler	: register( s0 );
uniform sampler g_DepthSampler		: register( s1 );
uniform float   g_SoftParticleScale;
uniform float   g_SoftParticleContrast;

    float4 ProcessPixel( VSOUT _input )
    {
		const float ZEPSILON = 0.001f;
    
		float4 OutColor = tex2D( g_TextureSampler, _input.TexCoord0 ) * _input.Diffuse;
		clip( OutColor.a - ZEPSILON );
		
		float SceneDepth = clamp(1.0f - tex2D( g_DepthSampler, _input.TexCoord1.xy ).b, 0.0f, 1.0f);
		float ZDiff = SceneDepth - _input.TexCoord1.z;
		
		float ZDiffScale = ZDiff * g_SoftParticleScale;
		bool IsAboveHalf = ZDiffScale > 0.5f;
		float ToRaise = saturate( 2 * (IsAboveHalf ? 1-ZDiffScale : ZDiffScale) );
		float c = 0.5 * pow( ToRaise, g_SoftParticleContrast );
		c = IsAboveHalf ? 1-c : c;
		
		clip( c * ZDiff - ZEPSILON );
		
		return float4( OutColor.rgb, OutColor.a * c * 1.0f );
	}